package EnterpriseAlgorithm.Stack_Queue.Code.RealizeBetweenS_And_Q;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.NoSuchElementException;

class MyStack_IV {
    Deque<Integer> que1;

    public MyStack_IV() {
        que1 = new ArrayDeque<>();
    }

    /**
     * Push element x onto stack.
     */
    public void push(int x) {
        que1.addLast(x);
    }

    /**
     * Removes the element on top of the stack and returns that element.
     */
    public int pop() {
        if (que1.isEmpty()) {
            throw new NoSuchElementException("Queue is empty");
        } else {
            return que1.pollLast();
        }
    }

    /**
     * Get the top element.
     */
    public int top() {
        if (que1.isEmpty()) {
            throw new NoSuchElementException("Queue is empty");
        } else {
            return que1.peekLast();
        }

    }

    /**
     * Returns whether the stack is empty.
     */
    public boolean empty() {
        return que1.isEmpty();
    }
}
